{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## import"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import tensorflow.examples.tutorials.mnist.input_data as input_data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"\\n%matplotlib inline\\nplt.rcParams['figure.figsize'] = (5.0, 4.0) # set default size of plots\\nplt.rcParams['image.interpolation'] = 'nearest'\\nplt.rcParams['image.cmap'] = 'gray'\\n\""
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "\"\"\"\n",
    "%matplotlib inline\n",
    "plt.rcParams['figure.figsize'] = (5.0, 4.0) # set default size of plots\n",
    "plt.rcParams['image.interpolation'] = 'nearest'\n",
    "plt.rcParams['image.cmap'] = 'gray'\n",
    "\"\"\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1 - Datasets"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "WARNING:tensorflow:From <ipython-input-3-060114859bc5>:1: read_data_sets (from tensorflow.contrib.learn.python.learn.datasets.mnist) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "Please use alternatives such as official/mnist/dataset.py from tensorflow/models.\n",
      "WARNING:tensorflow:From c:\\program files (x86)\\microsoft visual studio\\shared\\python36_64\\lib\\site-packages\\tensorflow\\contrib\\learn\\python\\learn\\datasets\\mnist.py:260: maybe_download (from tensorflow.contrib.learn.python.learn.datasets.base) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "Please write your own downloading logic.\n",
      "WARNING:tensorflow:From c:\\program files (x86)\\microsoft visual studio\\shared\\python36_64\\lib\\site-packages\\tensorflow\\contrib\\learn\\python\\learn\\datasets\\mnist.py:262: extract_images (from tensorflow.contrib.learn.python.learn.datasets.mnist) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "Please use tf.data to implement this functionality.\n",
      "Extracting datasets/train-images-idx3-ubyte.gz\n",
      "WARNING:tensorflow:From c:\\program files (x86)\\microsoft visual studio\\shared\\python36_64\\lib\\site-packages\\tensorflow\\contrib\\learn\\python\\learn\\datasets\\mnist.py:267: extract_labels (from tensorflow.contrib.learn.python.learn.datasets.mnist) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "Please use tf.data to implement this functionality.\n",
      "Extracting datasets/train-labels-idx1-ubyte.gz\n",
      "WARNING:tensorflow:From c:\\program files (x86)\\microsoft visual studio\\shared\\python36_64\\lib\\site-packages\\tensorflow\\contrib\\learn\\python\\learn\\datasets\\mnist.py:110: dense_to_one_hot (from tensorflow.contrib.learn.python.learn.datasets.mnist) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "Please use tf.one_hot on tensors.\n",
      "Extracting datasets/t10k-images-idx3-ubyte.gz\n",
      "Extracting datasets/t10k-labels-idx1-ubyte.gz\n",
      "WARNING:tensorflow:From c:\\program files (x86)\\microsoft visual studio\\shared\\python36_64\\lib\\site-packages\\tensorflow\\contrib\\learn\\python\\learn\\datasets\\mnist.py:290: DataSet.__init__ (from tensorflow.contrib.learn.python.learn.datasets.mnist) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "Please use alternatives such as official/mnist/dataset.py from tensorflow/models.\n"
     ]
    }
   ],
   "source": [
    "mnist = input_data.read_data_sets(\"datasets/\", one_hot=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "train_x_orig,train_y_orig,test_x_orig,test_y_orig=mnist.train.images,mnist.train.labels,mnist.test.images,mnist.test.labels"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "y= 7\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAP8AAAD8CAYAAAC4nHJkAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvIxREBQAADVVJREFUeJzt3X+s1fV9x/HXC7yipT8mtSAiE3SszpoU2qvdtGldjUZNE+wSjcR06DpxaclsZpY5kg3+aWK62c41WxesrJBUa5OWyhJiy2gTbDREsAbtcJUhWoRwsdSoy4rAfe+P+6W51Xs+53LO95zvub6fj4Scc77v7/d83574up9zzuec83FECEA+05puAEAzCD+QFOEHkiL8QFKEH0iK8ANJEX4gKcIPJEX4gaRO6+fJTveMOEMz+3lKIJVf63/1Zhz1ZPbtKvy2r5V0n6Tpkr4REfeU9j9DM/UxX9XNKQEUbI+tk96346f9tqdL+hdJ10m6WNIy2xd3en8A+qub1/yXSdoTEXsj4k1J35a0tJ62APRaN+GfJ+kX427vr7b9FtsrbO+wveOYjnZxOgB16ib8E72p8LbvB0fE2ogYjojhIc3o4nQA6tRN+PdLmj/u9nmSDnTXDoB+6Sb8T0paZHuh7dMl3SxpUz1tAei1jqf6IuK47ZWSfqCxqb51EfGz2joD0FNdzfNHxGZJm2vqBUAf8fFeICnCDyRF+IGkCD+QFOEHkiL8QFKEH0iK8ANJEX4gKcIPJEX4gaQIP5AU4QeSIvxAUoQfSIrwA0kRfiApwg8kRfiBpAg/kBThB5Ii/EBShB9IivADSRF+ICnCDyRF+IGkCD+QFOEHkupqlV7b+yS9LumEpOMRMVxHUwB6r6vwV/44Il6p4X4A9BFP+4Gkug1/SPqh7Z22V9TREID+6PZp/xURccD2bElbbD8XEdvG71D9UVghSWfoXV2eDkBduhr5I+JAdTkiaaOkyybYZ21EDEfE8JBmdHM6ADXqOPy2Z9p+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STK0s3+tgV+mpEE+GfJ+kX427v12At+R2Sfmh7p+0VTTczgTknV0aqLmc33M9btV25uZ/esrL0wDx2nax4Xbcmwj/R6j+DNOVwRUR8RNJ1kr5QPb3F5Exq5eZ+mWBl6YHQ6YrXdWsi/PslzR93+zxJBxroY0IRcaC6HJG0UYO3+vChk4ukVpcjDffzG4O0cvNEK0trAB67QVrxuonwPylpke2Ftk+XdLOkTQ308Ta2Z1ZvxMj2TEnXaPBWH94kaXl1fbmkRxrs5bcMysrNrVaWVsOP3aCteN3Ih3yqqYx/kjRd0rqI+FLfm5iA7Qs0NtpLY4uYPthkb7YfknSlxr71dUjSaknfl/QdSb8r6SVJN0ZE3994a9HblTrFlZt71FurlaW3q8HHrs4Vr2vph0/4ATnxCT8gKcIPJEX4gaQIP5AU4QeSIvxAUoQfSIrwA0n9P+ZmufOLGaSkAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "index = 25\n",
    "plt.imshow(train_x_orig[index].reshape(28,28))\n",
    "print(\"y= \"+str(int(np.squeeze(np.dot(train_y_orig[index].reshape(1,-1),np.array([0,1,2,3,4,5,6,7,8,9]).reshape(-1,1))))))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The shape of train_x is (784, 2000)\n",
      "The shape of train_y is (10, 2000)\n",
      "The shape of test_x is (784, 10000)\n",
      "The shape of test_y is (10, 10000)\n"
     ]
    }
   ],
   "source": [
    "train_x=train_x_orig[0:2000].T\n",
    "train_y=train_y_orig[0:2000].T\n",
    "test_x=test_x_orig.T\n",
    "test_y=test_y_orig.T\n",
    "print(\"The shape of train_x is (\"+ str(train_x.shape[0])+', '+str(train_x.shape[1])+')')\n",
    "print(\"The shape of train_y is (\"+ str(train_y.shape[0])+', '+str(train_y.shape[1])+')')\n",
    "print(\"The shape of test_x is (\"+ str(test_x.shape[0])+', '+str(test_x.shape[1])+')')\n",
    "print(\"The shape of test_y is (\"+ str(test_y.shape[0])+', '+str(test_y.shape[1])+')')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2 - L-layers init paras"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "def init_paras(X,Y,lims):\n",
    "    np.random.seed(0)\n",
    "    paras={}\n",
    "    L=len(lims)\n",
    "    \n",
    "    paras[\"W1\"]=np.random.randn(lims[0],X.shape[0])*0.01\n",
    "    paras[\"b1\"]=np.zeros((lims[0],1))\n",
    "    for l in range(1,L):\n",
    "        paras[\"W\"+str(l+1)]=np.random.randn(lims[l],lims[l-1])*0.01\n",
    "        paras[\"b\"+str(l+1)]=np.zeros((lims[l],1))\n",
    "    paras[\"W\"+str(L+1)]=np.random.randn(Y.shape[0],lims[L-1])*0.01\n",
    "    paras[\"b\"+str(L+1)]=np.zeros((Y.shape[0],1))\n",
    "    return paras"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3 - L-layers forward propagate"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "def relu(Z):\n",
    "    return np.maximum(0,Z)\n",
    "def sigmoid(Z):\n",
    "    return 1/(1+np.exp(-Z))\n",
    "def linear_forward(A_prev,W,b,activation):\n",
    "    Z=np.dot(W,A_prev)+b\n",
    "    A=activation(Z)\n",
    "    cache=(A_prev,W,b,Z)\n",
    "    return A,cache"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "def forward_propagate(X,paras):\n",
    "    L=len(paras)//2\n",
    "    caches=[]\n",
    "    A=X\n",
    "    for l in range(1,L):\n",
    "        A,cache=linear_forward(A,paras[\"W\"+str(l)],paras[\"b\"+str(l)],relu)\n",
    "        caches.append(cache)\n",
    "    AL,cache=linear_forward(A,paras[\"W\"+str(L)],paras[\"b\"+str(L)],sigmoid)\n",
    "    caches.append(cache)\n",
    "    return AL,caches"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 4 - Compute cost"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "def compute_cost(AL,Y):\n",
    "    cost=np.sum(np.multiply(-np.log(AL),Y)+np.multiply(-np.log(1-AL),(1-Y)))/Y.shape[1]   \n",
    "    return cost"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 5 - Backward propagate"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "def linear_back(dA,cache):\n",
    "    A_prev,W,b,Z=cache\n",
    "    m=dA.shape[1]\n",
    "    dZ=relu_back(dA,Z)\n",
    "    dW=np.dot(dZ,A_prev.T)/m\n",
    "    dA_prev=np.dot(W.T,dZ)\n",
    "    db=np.sum(dZ,axis = 1, keepdims = True)/m\n",
    "    return dW,dA_prev,db\n",
    "def relu_back(dA,Z):\n",
    "    dZ = np.array(dA, copy=True)\n",
    "    dZ[Z <= 0] = 0\n",
    "    return dZ"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "def backward_propagate(X,Y,caches,AL):\n",
    "    grads={}\n",
    "    L=len(caches)\n",
    "    m=Y.shape[1]\n",
    "    \n",
    "    A_prev,W,b,Z=caches[L-1]\n",
    "    grads[\"dW\"+str(L)]=np.dot(AL-Y,A_prev.T)/m\n",
    "    grads[\"db\"+str(L)]=np.sum(AL-Y,axis = 1, keepdims = True)/m\n",
    "    grads[\"dA\"+str(L-1)]=np.dot(W.T,AL-Y)\n",
    "    \n",
    "    for l in reversed(range(L-1)):\n",
    "        grads[\"dW\"+str(l+1)],grads[\"dA\"+str(l)],grads[\"db\"+str(l+1)]=linear_back(grads[\"dA\"+str(l+1)],caches[l])\n",
    "    return grads"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 6 - Updata paras"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "def updata_paras(paras,grads,learning_rate=0.6):\n",
    "    L=len(paras)//2\n",
    "    for l in range(1,L+1):\n",
    "        paras[\"W\"+str(l)]-=learning_rate*grads[\"dW\"+str(l)]\n",
    "        paras[\"b\"+str(l)]-=learning_rate*grads[\"db\"+str(l)]\n",
    "    return paras"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "def model(X, Y, layers_dims, learning_rate = 0.3, num_iterations = 3000, print_cost=True):\n",
    "    costs = []\n",
    "    paras=init_paras(train_x,train_y,layers_dims)\n",
    "    for i in range(0, num_iterations):\n",
    "        AL,caches=forward_propagate(train_x,paras)\n",
    "        cost=compute_cost(AL,train_y)\n",
    "        grads=backward_propagate(train_x,train_y,caches,AL)\n",
    "        paras=updata_paras(paras,grads,learning_rate)\n",
    "        if print_cost and i % 100 == 0:\n",
    "            print (\"Cost after iteration %i: %f\" %(i, cost))\n",
    "            costs.append(cost)\n",
    "            \n",
    "    plt.plot(np.squeeze(costs))\n",
    "    plt.ylabel('cost')\n",
    "    plt.xlabel('iterations (per tens)')\n",
    "    plt.title(\"Learning rate =\" + str(learning_rate))\n",
    "    plt.show()\n",
    "    return paras"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "def predict(X,Y,paras):\n",
    "    AL,_=forward_propagate(X,paras)\n",
    "    m = X.shape[1]\n",
    "\n",
    "    p=AL.argmax(0)\n",
    "    y=Y.argmax(0)\n",
    "    \n",
    "    num=0\n",
    "    for i in range(len(p)):\n",
    "        if p[i]==y[i]:\n",
    "            num+=1\n",
    "    print(\"Accuracy: \"  + str(num/m))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Cost after iteration 0: 6.931426\n",
      "Cost after iteration 100: 3.253433\n",
      "Cost after iteration 200: 3.210701\n",
      "Cost after iteration 300: 2.936799\n",
      "Cost after iteration 400: 2.794458\n",
      "Cost after iteration 500: 2.733623\n",
      "Cost after iteration 600: 2.659134\n",
      "Cost after iteration 700: 2.522992\n",
      "Cost after iteration 800: 2.046296\n",
      "Cost after iteration 900: 1.611268\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXwAAAEWCAYAAABliCz2AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvIxREBQAAIABJREFUeJzt3Xl8HHd9//HXZ3VaknWsLDuOD1myc5LLsWMpEHKQQIFSjpK2yQ8CBUoargLlVwr8+ij82h99tAVaQglH7tBAOELSQqAB4twJtmMnsR18EFu+HVvypfvW5/fHjOy1ItmyrdXs7ryfj8c+tDs7O/PZTfye2c/MfsfcHRERyX2JqAsQEZHJocAXEYkJBb6ISEwo8EVEYkKBLyISEwp8EZGYUOBLTjGz/zGz90ddh0gmUuDLhDCzrWZ2TdR1uPtb3P2eqOsAMLPHzewvJmE9RWZ2p5m1mdkeM/vrY8x7npn9ysz2mZl+hBMzCnzJGmaWH3UNwzKpFuBLwBlALXAV8Fkze/MY8/YDPwY+NDmlSSZR4EvamdnbzOxFMztkZs+a2QUpz33OzDabWbuZrTOzd6U89+dm9oyZ/buZHQC+FE572sy+amYHzWyLmb0l5TWH96rHMW+dmT0ZrvsRM7vFzO4d4z1caWY7zexvzWwPcJeZVZnZQ2bWEi7/ITObHc7/ZeD1wDfNrMPMv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RIttXRETsw/EVzwOlvMBT6nsBfQHr6ISGxoD19EJCYU+CIiMaHAFxGJCQW+iEhMKPBFRGLi/wO89Hzer0HpVQAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "layers_dims=[8,7]\n",
    "paras=model(train_x, train_y, layers_dims,learning_rate = 0.1,num_iterations = 1000)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Accuracy: 0.791\n"
     ]
    }
   ],
   "source": [
    "pred_train = predict(train_x, train_y, paras)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Accuracy: 0.7259\n"
     ]
    }
   ],
   "source": [
    "pred_test=predict(test_x,test_y,paras)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
